﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SpringStudio.Common;
using SpringStudio.DAL;

namespace Sdepci.InfoCode.BLL.CodeIndex
{
    /// <summary>
    /// 编码字典表
    /// </summary>
    public class Dict
    {
        #region 属性定义

        private string _dictGuid;
        /// <summary>
        /// 字典Guid
        /// </summary>
        public string DictGuid
        {
            get { return this._dictGuid; }
        }

        private string _parentDictGuid;
        /// <summary>
        /// 父字典Guid
        /// </summary>
        public string ParentDictGuid
        {
            get { return this._parentDictGuid; }
        }

        private string _cateGuid;
        /// <summary>
        /// 索引Guid
        /// </summary>
        public string CateGuid
        {
            get { return this._cateGuid; }
        }

        private string _dictCode;
        /// <summary>
        /// 字典代码
        /// </summary>
        public string DictCode
        {
            get { return this._dictCode; }
        }

        private string _dictText;
        /// <summary>
        /// 字典文本
        /// </summary>
        public string DictText
        {
            get { return this._dictText; }
        }

        private string _dictDesc;
        /// <summary>
        /// 中文描述
        /// </summary>
        public string DictDesc
        {
            get { return this._dictDesc; }
        }

        private int _seq;
        /// <summary>
        /// 显示次序
        /// </summary>
        public int Seq
        {
            get { return this._seq; }
        }

        #endregion

        #region 构造方法

        public Dict(string dictGuid)
        {
            this._dictGuid = dictGuid;
            try
            {
                string sql = "Select DictGuid,ParentDictGuid,CateGuid,DictCode,DictText,DictDesc,Seq From InfoCodeDicts Where DictGuid=@DictGuid";
                DataSet ds = SqlHelper.ExecuteDataSet(ConnectionString.Default, CommandType.Text, sql,
                    SqlHelper.NewSqlParameter("@DictGuid", this._dictGuid));
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow row = ds.Tables[0].Rows[0];
                    this._parentDictGuid = row["ParentDictGuid"].ToString();
                    this._cateGuid = row["CateGuid"].ToString();
                    this._dictCode = row["DictCode"].ToString();
                    this._dictText = row["DictText"].ToString();
                    this._dictDesc = row["DictDesc"].ToString();
                    this._seq = int.Parse(row["Seq"].ToString());

                }
                else
                {
                    throw new Exception("没有找到该值对应的详细记录！（参数：DictGuid'" + this._dictGuid + "'）");
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }

        public Dict(string dictGuid, string parentDictGuid, string cateGuid, string dictCode, string dictText, string dictDesc, int seq)
        {
            this._dictGuid = dictGuid;
            this._parentDictGuid = parentDictGuid;
            this._cateGuid = cateGuid;
            this._dictCode = dictCode;
            this._dictText = dictText;
            this._dictDesc = dictDesc;
            this._seq = seq;
        }

        #endregion
    }
}